<template>
    <movable-area style="width: 100vw; height: 100vh">
        <movable-view
            v-if="showIcons.includes('share')"
            class="customer-service-main"
            direction="all"
            :disabled="disabled"
            :x="iconInfo.screenWidth * 0.8"
            :y="iconInfo.screenHeight * 0.7 - (iconInfo.screenWidth <= 320 ? 58 : 68)">
            <view @tap="handleSharePopup">
                <image :src="getImgOssUrl('/ui-prod-2.12.0/share_home_icon.png')" class="link_icon"></image>
                <view class="text">分享</view>
            </view>
        </movable-view>
        <movable-view
            v-if="showIcons.includes('service')"
            direction="all"
            :disabled="disabled"
            :x="iconInfo.screenWidth * 0.8"
            :y="iconInfo.screenHeight * 0.7"
            class="customer-service-main">
            <view @click="goOnlineServer">
                <image :src="getImgOssUrl('/ui-prod-2.3.0/online-customer-service@2x.png')" class="link_icon"></image>
                <view class="text">客服</view>
            </view>
        </movable-view>
    </movable-area>
    <SharePopup
        v-if="showIcons.includes('share')"
        ref="sharePopupRef"
        :shareAppMessage="$attrs.shareAppMessage"></SharePopup>
</template>
<script setup>
import { reactive, ref } from 'vue';
import router from '@/router';
import storage from '@/commons/storage';
import { getImgOssUrl } from '@/commons/utils';
import SharePopup from '@/components/sharePopup';

const props = defineProps({
    // todo:以后做成可定制化的，本期先写死
    disabled: {
        type: Boolean,
        default: false // 是否禁止拖动
    },
    showIcons: {
        type: Array,
        default: () => ['service']
    }
});

let iconInfo = reactive({});
const getIconInfo = () => {
    uni.getSystemInfo({
        success: res => {
            iconInfo = res;
        }
    });
};
getIconInfo();
const goOnlineServer = () => {
    const url = JSON.parse(storage.get('openServerMes'))?.serviceLink;
    const corpId = JSON.parse(storage.get('openServerMes'))?.corpId;
    /* eslint-disable */
    // #ifdef  MP-WEIXIN
    wx.openCustomerServiceChat({
        extInfo: {
            url
        },
        corpId // 企业id 必须和你小程序上的一致
    });
    // #endif
    /* eslint-enable */
};
// 打开分享
// 分享邀请
const sharePopupRef = ref();
const handleSharePopup = () => {
    sharePopupRef?.value?.handlePopup();
};
</script>
<style lang="scss" scoped>
.customer-service-main {
    position: fixed;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 109rpx;
    height: 109rpx;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 11rpx 29rpx 0 rgba(204, 204, 204, 1);
    .link_icon {
        width: 43rpx;
        height: 43rpx;
    }
    .text {
        font-size: 22rpx;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #585858;
    }
}
</style>
